package operations;

import computer.Operand;
import computer.ProgramCounter;
import computer.Memory;

public class JumpEq implements Operation {
	private Operand o1, o2;
	int jumpTo;

	public JumpEq(int jumpTo, Operand o1, Operand o2) {
		this.o1 = o1;
		this.o2 = o2;
		this.jumpTo = jumpTo;
	}

	public void execute(Memory memory, ProgramCounter programCounter) {
		if (o1.getValue(memory).equals(memory, o2)) {
			programCounter.set(jumpTo);
		} else {
			programCounter.increase();
		}
	}
	
	public String toString() {
		StringBuilder outputString = new StringBuilder();
		outputString.append("JEQ ");
		outputString.append(jumpTo + " ");
		outputString.append(o1 + " ");
		outputString.append(o2);
		
		return outputString.toString();
	}
}
